package org.roger.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class FileUtil {
	
	public static String getText(String filePath){
		try {
			InputStreamReader read = new InputStreamReader(new FileInputStream(filePath),"UTF-8");
			return getText(read);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getText(InputStreamReader read){
		String content = "";
		StringBuffer sb = new StringBuffer();
		BufferedReader br = new BufferedReader(read);
		try {
			String s = br.readLine();
			
			while(s != null){
				sb.append(s);
				s = br.readLine();
			}
			content = sb.toString();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return content;
	}
	
	public static void main(String[] args) {
		//File file = new File("E:/lucene/file/1.txt");
		FileUtil.getText("E:/lucene/file/1.txt");
//		System.out.println(file.getAbsolutePath());
//		System.out.println(file.getName());
	}

}
